package com.junxonline.plat.dao.repository;

import com.junxonline.plat.dao.model.Charge;
import com.junxonline.plat.dao.model.Household;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface ChargeRepository extends JpaRepository<Charge, Long>, JpaSpecificationExecutor<Charge> {

    Charge findByChargeId(Long attenceId);

    List<Charge> findByChargeIdIn(Long[] attenceIds);

    @Query(value =
            "SELECT charge.charge_id, charge.household_id, SUM(charge.charge_money) AS charge_money, household.household_name, household.household_no, household.household_phone FROM plat_charge charge " +
            "LEFT JOIN plat_household household ON household.household_id = charge.household_id " +
            "AND household.is_household = 1 GROUP BY charge.household_id ORDER BY charge.household_id ASC", nativeQuery = true)
    List<Map<String, Object>> findByNeedChargeHousehold();

}
